-
-
Notifications
You must be signed in to change notification settings - Fork 224
[hsskey] WEEK 1 solutions #1168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map과 set을 너무 잘 사용하시고, 코드도 깔끔하고 읽기 쉽게 작성하십니다 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num - 1
을 확인해서 시작이 되는 값을 찾는 것이 좋은것같습니다!
발상은 비슷한데 조금 다른 제 방식은 num에서 while을 +1로도 가고, -1 로도 가게했습니다. 그리고 각각 반복할 때, numSet에서 currentNum을 지워주구요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 관점에서 생각못해본 부분인데 피드백 감사합니다.
처음 아이디어를 떠올릴땐, 좌표선상에 연속된 sequence 그룹을 펼쳐놓았을때,
해당 그룹들의 이전 이웃값(n-1)이 없을때 sequence 그룹을 만들 수 있겠다 생각해서 표현해놓은 부분입니다.
말씀해주신대로 while문에서 +1이나 -1로도 가게할 수도 있군요👍
for(let i = 0; i < nums.length; i++) { | ||
if(map.has(nums[i])) { | ||
const prevVal = map.get(nums[i]) | ||
map.set(nums[i], prevVal + 1) | ||
} else { | ||
map.set(nums[i], 1) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(개인적인 생각입니다)
아래 코드에서는 Array메서드를 사용하여 명시적으로 해주셔서 여기도 forEach로 사용하는게 조금 더 통일성이 있을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은 피드백 감사합니다 🙇♂️
말씀해주신 것처럼 forEach를 쓰면 코드가 더 간결하고 Array 메서드 체이닝과도 일관성이 생길 수 있다는 점 공감합니다.
다만 저는 반복문 처리에서의 미세한 성능 차이를 고려해서 for 루프를 선호하는 편입니다. (주로 실무에서도)
특히 입력 배열이 커질 경우 forEach의 콜백 호출 비용이 누적될 수 있고, break/continue 등의 흐름 제어가 제한되는 점도 고려하고 있습니다.
물론 이번 문제에선 실제 성능 차이는 거의 없겠지만, 개인적으로는 성능 상 이점을 조금이라도 취할 수 있는 구조를 습관화하는 쪽을 택하고 있습니다.
다시 한 번 스타일 일관성에 대한 피드백 감사드려요. 더 고민해볼 수 있는 좋은 계기가 됐습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기는 제가 아직 안풀어서 우선 approve 하고 추후 확인하겠습니다.
* @return {number} | ||
*/ | ||
var rob = function(nums) { | ||
if (nums.length === 0) return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 당연히 length는 0이 아니겠지하고 조건을 안보고 진행했었는데 이부분 까지 꼼꼼하게 생각하신점이 좋습니다👍
(저한테는 다행히 조건에 1 <= nums.length <= 100
가 있어서 통과가 된것같네요.)
@lhc0506 꼼꼼한 리뷰 감사합니다 |
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!